'''
测试BlfOb
'''

from BlfIoObjs import *
from BlfIo import BlfObjFromBytes, BlfIo
import random
import time

if __name__ == '__main__':
    blfio_ = BlfIo()
    # t_ = time.time()
    # for i_ in range(10000):
    #     can_fd_message_ = CanFdMessagePy(3, dlc=15, id=0x4E, data=[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, ])
    #     data_ = can_fd_message_.ToBytes()
    #     obj_ = BlfObjFromBytes(data_)
    #     if (isinstance(obj_, CanFdMessagePy)):
    #         # print(obj_.ToDict())
    #         a_ = obj_.ToDict()
    # print(time.time() - t_)
    res_ = blfio_.OpenLogFile('Z:/log_{0}.blf'.format(time.time()))
    if (res_ == 0):
        objs_ = [
            CanFdMessagePy(3, dlc=15, id=0x4E, data=[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, ]),
            CanFdMessage64Py(2, 5, id=0x66, dir=1, data=[0x11, 0x22, 0x33, 0x44, 0x55]),
            CanMessagePy(4, 1, 4, 0x98, [0x01, 0xFF, 0x45, 0x23]),
            CanMessage2Py(8, 1, 2, 0x55, [0x44, 0x88]),
            LinMessagePy(3, 0x3F, 2, [0x11, 0x44], dir=1),
            # LinMessage2Py([0x44, 0x55, 0x66], dir=0,)
            EthernetFramePy([0x02, 0x80, 0x5E, 0x1F, 0x01, 0x02], 4, [0x02, 0x80, 0x5F, 0x1F, 0x01, 0x02], payLoad=[0x02, 0x03], payLoadLength=2)
        ]
        for i_ in range(1000000):
            for obj_ in objs_:
                # blfio_.LogNext(obj_, time.time_ns())
                blfio_.LogNext(obj_)
                # data_ = obj_.ToBytes()
                # obj_ = BlfObjFromBytes(data_)
                # if (isinstance(obj_, CanFdMessagePy)):
                # print('----------')
                # print(type)
                # print(obj_.ToDict())
        blfio_.CloseLogFile()
            
    